
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <amanita/aMath.h>
#include "../Main.h"
#include "../occult/Occult.h"
#include "PlanetsDlg.h"
#include "HoroscopeChartPage.h"
#include "Horoscope.h"


gboolean PlanetsDlg::delete_event_callback(GtkWidget *widget,GtkWidget *event,gpointer data) {
	PlanetsDlg *dlg = (PlanetsDlg *)data;
	dlg->hide();
	return TRUE;
}

void PlanetsDlg::ok_clicked_callback(GtkWidget *widget,gpointer data) {
app.printf("PlanetsDlg::ok_clicked_callback()");
	PlanetsDlg *dlg = (PlanetsDlg *)data;
	dlg->hide();
}

void PlanetsDlg::cancel_clicked_callback(GtkWidget *widget,gpointer data) {
app.printf("PlanetsDlg::cancel_clicked_callback()");
	PlanetsDlg *dlg = (PlanetsDlg *)data;
	dlg->hide();
}


PlanetsDlg::PlanetsDlg(GtkWindow *parent) {
	int i;
	GtkWidget *widget;
	GtkWidget *frame;
	GtkWidget *hbox,*vbox;

	gtk.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title(GTK_WINDOW(gtk.window),app.get("title.planetsdlg"));
	gtk_window_set_transient_for(GTK_WINDOW(gtk.window),parent);
	gtk_window_set_resizable(GTK_WINDOW(gtk.window),FALSE);
	gtk_window_set_position(GTK_WINDOW(gtk.window),GTK_WIN_POS_CENTER);
	//gtk_window_set_icon(GTK_WINDOW(gtk.window),app.createPixbuf(IMAGES_PATH "icons/icon16.png"));
	gtk_container_set_border_width(GTK_CONTAINER(gtk.window),2);
	g_signal_connect(G_OBJECT(gtk.window),"delete_event",G_CALLBACK(delete_event_callback),this);

	hbox = gtk_hbox_new(FALSE,2);
	{
		frame = gtk_frame_new(app.get("planets"));
		vbox = gtk_vbox_new(FALSE,2);
		for(i=ASTRO_SUN; i<=ASTRO_PLUTO; i++) {
			widget = gtk_check_button_new_with_label(app.occult.planetName(i));
			gtk_box_pack_start(GTK_BOX(vbox),widget,FALSE,FALSE,0);
		}
		gtk_container_add(GTK_CONTAINER(frame),vbox);
		gtk_box_pack_start(GTK_BOX(hbox),frame,FALSE,TRUE,0);

		frame = gtk_frame_new(app.get("planets.minor"));
		vbox = gtk_vbox_new(FALSE,2);
		for(i=ASTRO_CHIRON; i<=ASTRO_VESTA; i++) {
			widget = gtk_check_button_new_with_label(app.occult.planetName(i));
			gtk_box_pack_start(GTK_BOX(vbox),widget,FALSE,FALSE,0);
		}
		gtk_container_add(GTK_CONTAINER(frame),vbox);
		gtk_box_pack_start(GTK_BOX(hbox),frame,FALSE,TRUE,0);

		const int points[] = { ASTRO_NNODE,ASTRO_SNODE,ASTRO_VERTEX,ASTRO_EASTPOINT,ASTRO_FORTUNE,ASTRO_ASCENDANT,ASTRO_MC,-1 };
		frame = gtk_frame_new(app.get("planets.points"));
		vbox = gtk_vbox_new(FALSE,2);
		for(i=0; points[i]!=-1; i++) {
			widget = gtk_check_button_new_with_label(app.occult.planetName(points[i]));
			gtk_box_pack_start(GTK_BOX(vbox),widget,FALSE,FALSE,0);
		}
		gtk_container_add(GTK_CONTAINER(frame),vbox);
		gtk_box_pack_start(GTK_BOX(hbox),frame,FALSE,TRUE,0);
	}

	vbox = gtk_vbox_new(FALSE,2);
	gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,0);

	hbox = gtk_hbox_new(FALSE,2);
	{
		widget = gtk_button_new_with_label(app.get("ok"));
		g_signal_connect(G_OBJECT(widget),"clicked",G_CALLBACK(ok_clicked_callback),this);
		gtk_widget_set_size_request(widget,80,-1);
		gtk_box_pack_start(GTK_BOX(hbox),widget,FALSE,FALSE,2);
		widget = gtk_button_new_with_label(app.get("cancel"));
		g_signal_connect(G_OBJECT(widget),"clicked",G_CALLBACK(cancel_clicked_callback),this);
		gtk_widget_set_size_request(widget,80,-1);
		gtk_box_pack_start(GTK_BOX(hbox),widget,FALSE,FALSE,2);
	}
	gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,0);

	gtk_widget_show_all(vbox);
	gtk_container_add(GTK_CONTAINER(gtk.window),vbox);
}

PlanetsDlg::~PlanetsDlg() {
	gtk_widget_destroy(gtk.window);
}

void PlanetsDlg::show() {
	gtk_widget_show(gtk.window);
	
}

void PlanetsDlg::hide() {
	gtk_widget_hide(gtk.window);
}


/*
void PlanetsDlg::create(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam) {
fprintf(out,"PlanetsDlg::create()\n");
fflush(out);
	Window::create(hwnd,message,wParam,lParam);
	HWND h;
	int x,y;

	setFont(getFont(FW_NORMAL,13,"Tahoma"));

	createButton(x=5,y=5,150,210,IDC_STATIC,"Planeter",BS_GROUPBOX|WS_VISIBLE);
	for(int i=ASTRO_SUN,j=0; i<=ASTRO_PLUTO; i++,j++)
		createButton(x+10,y+15+j*19,120,16,IDC_ASTRO_PLANETSHOW1+j,occult->planet(i),BS_AUTOCHECKBOX|WS_GROUP|WS_TABSTOP|WS_VISIBLE);

	createButton(x=162,y=5,150,210,IDC_STATIC,"Mindre Planeter",BS_GROUPBOX|WS_VISIBLE);
	for(int i=ASTRO_CHIRON,j=0; i<=ASTRO_VESTA; i++,j++)
		createButton(x+10,y+15+j*19,120,16,IDC_ASTRO_PLANETSHOW15+j,occult->planet(i),BS_AUTOCHECKBOX|WS_GROUP|WS_TABSTOP|WS_VISIBLE);

	createButton(x=319,y=5,150,210,IDC_STATIC,"Planet Punkter",BS_GROUPBOX|WS_VISIBLE);
	createButton(x+10,y+15,120,16,IDC_ASTRO_PLANETSHOW11,"Månens Norra Nod",BS_AUTOCHECKBOX|WS_GROUP|WS_TABSTOP|WS_VISIBLE);
	createButton(x+10,y+34,120,16,IDC_ASTRO_PLANETSHOW13,"Månens Södra Nod",BS_AUTOCHECKBOX|WS_GROUP|WS_TABSTOP|WS_VISIBLE);
	createButton(x+20,y+53,120,16,IDC_ASTRO_PLANETSHOW12,"Använd Sann Nod",BS_AUTOCHECKBOX|WS_GROUP|WS_TABSTOP|WS_VISIBLE);

	createButton(x+10,y+85,120,16,IDC_ASTRO_PLANETSHOW20,"Vertex",BS_AUTOCHECKBOX|WS_GROUP|WS_TABSTOP|WS_VISIBLE);
	createButton(x+10,y+104,120,16,IDC_ASTRO_PLANETSHOW21,"Östpunkten",BS_AUTOCHECKBOX|WS_GROUP|WS_TABSTOP|WS_VISIBLE);
	createButton(x+10,y+123,120,16,IDC_ASTRO_PLANETSHOW22,"Lyckans Lott",BS_AUTOCHECKBOX|WS_GROUP|WS_TABSTOP|WS_VISIBLE);

	createButton(x+10,y+155,120,16,IDC_ASTRO_PLANETSHOW23,"Ascendenten",BS_AUTOCHECKBOX|WS_GROUP|WS_TABSTOP|WS_VISIBLE);
	createButton(x+10,y+174,120,16,IDC_ASTRO_PLANETSHOW24,"Medium Coeli",BS_AUTOCHECKBOX|WS_GROUP|WS_TABSTOP|WS_VISIBLE);

	y = 222;
	createButton(154,y,80,22,IDOK,"OK",BS_DEFPUSHBUTTON|WS_TABSTOP|WS_VISIBLE);
	createButton(240,y,80,22,IDCANCEL,"Avbryt",BS_PUSHBUTTON|WS_TABSTOP|WS_VISIBLE);


	char str[8];
	for(int i=0,n; i<256 && (n=Horoscope::planetsDefault[i]); i++) {
		switch(n) {
			case ASTRO_TNNODE:CheckDlgButton(hwnd,IDC_ASTRO_PLANETSHOW12,BST_CHECKED);n = ASTRO_NNODE;break;
			case ASTRO_TSNODE:CheckDlgButton(hwnd,IDC_ASTRO_PLANETSHOW12,BST_CHECKED);n = ASTRO_SNODE;break;
		}
		CheckDlgButton(hwnd,IDC_ASTRO_PLANETSHOW1+n-1,BST_CHECKED);
	}
fprintf(out,"PlanetsDlg::create()\n");
fflush(out);
}

bool PlanetsDlg::command(WPARAM wParam,LPARAM lParam) {
fprintf(out,"PlanetsDlg::command=%d\n",LOWORD(wParam));
fflush(out);
	switch(LOWORD(wParam)) {
		case IDOK:
		{
			HWND hwnd = getHWND(),h;
			int i,n=0,t=0;
			for(i=ASTRO_SUN; i<=ASTRO_MC; i++) {
				if(i!=ASTRO_TNNODE && i!=ASTRO_TSNODE &&
						IsDlgButtonChecked(hwnd,IDC_ASTRO_PLANETSHOW1+i-ASTRO_SUN)==BST_CHECKED) {
					if(i==ASTRO_NNODE || i==ASTRO_SNODE)
						t = IsDlgButtonChecked(hwnd,IDC_ASTRO_PLANETSHOW12)==BST_CHECKED;
					Horoscope::planetsDefault[n++] = i+t,t = 0;
				}
			}
			Horoscope::planetsDefault[n] = 0;
			closeDlg(IDOK);
			return true;
		}
		case IDCANCEL:closeDialog(IDCANCEL);return true;
	}
	return false;
}

*/

